#!/usr/bin/perl
use strict;
use warnings;
use autodie;

open VCF, "$ARGV[0]";
open INFO, "$ARGV[1]";

my ($info, $id);
while (<INFO>) {
	if (/^#/) {
		$info=$_;
		/ID=([a-zA-Z]+?),/;
		$id = $1;
		last;
	}else {
	die "Error: Info file should contain a header line start with ##.\n";
	}
}

my %data_row;
my $i = 0;
while (<INFO>) {
	if (/^[^#]/) {
		chomp;
		$i++;
		$data_row{$i}=$_;
	}
}


# my @number = qw(Number . 1 0);
# my @type = qw(String Integer Float Flag);
# my $info1='##INFO=<ID=DP,Number=1,Type=Integer,Description="Approximate read depth; some reads may have been filtered">'

while (<VCF>) {
	if (/^##/) {
		print;
	}elsif (/^#/) {
		print $info;
		print;
		last;
	}
}

my $j =0;
while (<VCF>) {
	if (/^[^#]/) {
		my @row = split /\t/, $_;
		# my $info = $row[7];
		$j++;
		$row[7].="\;$id=$data_row{$j}";
		foreach (0..($#row-1)) {
			print "$row[$_]\t";
		}
		print "$row[-1]";
	}
}

if ($i != $j) {
	die "Error: the two files cantain with different rows.\n";
}